package com.zhuozhou.jdyc.main.main.adapter;

import android.content.Context;
import android.view.View;

import com.bumptech.glide.Glide;
import com.zhuozhou.jdyc.R;
import com.zhuozhou.jdyc.base.BaseRecyclerViewAdapter;
import com.zhuozhou.jdyc.base.BaseViewHolder;
import com.zhuozhou.jdyc.databinding.BaterImageItemBinding;
import com.zhuozhou.jdyc.main.main.bean.BasicsYiHuoStopBean;
import com.zhuozhou.jdyc.util.apiUtil.StringUtil;

/**
 * Create by CherishTang on 2020/3/27 0027
 * describe:首页菜单adapter
 */
public class BarterImageAdapter extends BaseRecyclerViewAdapter<BasicsYiHuoStopBean, BaterImageItemBinding> {
    public OnImageItemClickListener mOnImageItemClickListener;

    public BarterImageAdapter(Context context) {
        super(context);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.bater_image_item;
    }

    @Override
    public void onBindViewHolder(BaseViewHolder baseViewHolder, int pos) {
        super.onBindViewHolder(baseViewHolder, pos);
        baseViewHolder.getBinding().getRoot().setOnClickListener(v -> {
            if (mOnImageItemClickListener != null) {
                mOnImageItemClickListener.onImageItemClick(baseViewHolder.getBinding().getRoot(), getRealPosition(baseViewHolder));
            }
        });
    }

    @Override
    public void onBindHolder(BaseViewHolder<BaterImageItemBinding> holder, int pos) {
        if (StringUtil.isNotEmpty(mList.get(pos).getImages()))
            Glide.with(mContext).load(mList.get(pos).getImages()).into(holder.getBinding().imageMerchant);
        else if (StringUtil.isNotEmpty(mList.get(pos).getImg()))
            Glide.with(mContext).load(mList.get(pos).getImg()).into(holder.getBinding().imageMerchant);
        else if (StringUtil.isNotEmpty(mList.get(pos).getSpec_image()))
            Glide.with(mContext).load(mList.get(pos).getSpec_image()).into(holder.getBinding().imageMerchant);
    }

    public void setOnImageItemClickListener(OnImageItemClickListener l) {
        mOnImageItemClickListener = l;
    }

    public interface OnImageItemClickListener {
        void onImageItemClick(View view, int position);
    }
}
